<!--河南星辰软件科技有限公司
@copyright Copyright (c) 2010~2022 All rights reserved.
-->
<template>
  <div class='app-container'>
    <el-form ref="form" :model="quo_price" :rules="rules" label-width="100px" id="mvcfm">
      <el-button @click="increaseOfferSubmit('')" type='success' size="mini"><i class='fa fa-check'></i>保存</el-button>
      <el-button @click="gotoPage('/crm/sale/contract/CartogramSaleContract?'+vueparams+'')" type='primary' size="mini"><i class='fa fa-reply'></i>返回</el-button>
      <div class="form-unit">
        <span class="mvc-title-left"> 添加新合同 </span>
      </div>
      <div>
        <el-row>
          <el-col :span="12">
            <el-form-item label="条形码" prop="quo_barcode">
              <el-input v-model="quo_price.quo_barcode" readonly />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="合同编号" prop="quo_num">
              <el-input v-model="quo_price.quo_num" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="合同主题" prop="quo_theme">
              <el-input v-model="quo_price.quo_theme" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="客户" prop="">
              {{quo_price.quo_client}}
              <el-button @click="popSelectCustomersSale('','quo_client')" type="success" size="mini"><i class="fa fa-edit"></i>选择</el-button>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="联系人" prop="">
              {{quo_price.quo_contact}}
              <el-button @click="popChooseContacts('','quo_contact')" type="success" size="mini"><i class="fa fa-edit"></i>选择</el-button>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="地址" prop="quo_address">
              <el-input type="textarea" v-model="quo_price.quo_address" ttparea=350></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="签订时间" prop="quo_finishdate">
              <el-date-picker v-model="quo_price.quo_finishdate" type="date" style='width:100%' value-format="yyyy-MM-dd" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="失效日期" prop="quo_faildate">
              <el-date-picker v-model="quo_price.quo_faildate" type="date" style='width:100%' value-format="yyyy-MM-dd" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="合同状态" prop="quo_state">
              <el-select style='width:100%' v-model="quo_price.quo_state">
                <el-option label="待执行" value="0" />
                <el-option label="执行中" value="1" />
                <el-option label="已完成" value="2" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </div>
      <div class="form-unit">
        <span class="mvc-title-left"> 列表条目 </span>
      </div>
      <el-table :data="s_top">
        <el-table-column label="操作" prop="" width="60">
          <template slot-scope="scope">
            <el-link @click="appendRow(s_top,scope)" type='primary'><i class='el-icon-plus' title='增加行' /></el-link>
            <el-link @click="delRow(s_top,scope)" type='danger'><i class='el-icon-minus' title='删除行' /></el-link>
          </template>
        </el-table-column>
        <el-table-column label="产品选择" prop="product_id">
          <template slot-scope="scope">
            {{scope.row.product_id}}
            <el-button @click="popProductChoce('product_id','pronum_prodece')" type="success" size="mini"><i class="fa fa-edit"></i>选择</el-button>
          </template>
        </el-table-column>
        <el-table-column label="数量" prop="">
          <template slot-scope="scope">
            <el-input v-model="scope.row.pronum_no" />
          </template>
        </el-table-column>
        <el-table-column label="数量单位" prop="">
          <template slot-scope="scope">
            <el-input v-model="scope.row.pronum_nuit" />
          </template>
        </el-table-column>
        <el-table-column label="单价" prop="price_pro">
          <template slot-scope="scope">
            <el-input v-model="scope.row.price_pro" />
          </template>
        </el-table-column>
        <el-table-column label="交货地点" prop="" width="50">
          <template slot-scope="scope">
            <el-input v-model="scope.row.pronum_address" />
          </template>
        </el-table-column>
        <el-table-column label="交货时间" prop="">
          <template slot-scope="scope">
            <el-date-picker v-model="scope.row.pronum_endate" type="date" style='width:100%' value-format="yyyy-MM-dd" />
          </template>
        </el-table-column>
        <el-table-column label="简要描述" prop="" width="20">
          <template slot-scope="scope">
            <el-input v-model="scope.row.pronum_remark" />
          </template>
        </el-table-column>
      </el-table>
      <div class="form-unit">
        <span class="mvc-title-left"> 甲乙双方责任 </span>
      </div>
      <el-table :data="s_top">
        <el-table-column label="操作" prop="" width="60">
          <template slot-scope="scope">
            <el-link @click="appendRow(s_top,scope)" type='primary'><i class='el-icon-plus' title='增加行' /></el-link>
            <el-link @click="delRow(s_top,scope)" type='danger'><i class='el-icon-minus' title='删除行' /></el-link>
          </template>
        </el-table-column>
        <el-table-column label="选择" prop="description">
          <template slot-scope="scope">
            {{scope.row.description}}
            <el-button @click="popResponsibilityChoice2('description','duty_remark')" type="success" size="mini"><i class="fa fa-edit"></i>选择</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="form-unit">
        <span class="mvc-title-left"> 付款方式 </span>
      </div>
      <el-table :data="s_top">
        <el-table-column label="操作" prop="" width="60">
          <template slot-scope="scope">
            <el-link @click="appendRow(s_top,scope)" type='primary'><i class='el-icon-plus' title='增加行' /></el-link>
            <el-link @click="delRow(s_top,scope)" type='danger'><i class='el-icon-minus' title='删除行' /></el-link>
          </template>
        </el-table-column>
        <el-table-column label="首次付款" prop="pay_first">
          <template slot-scope="scope">
            <el-input v-model="scope.row.pay_first" />
          </template>
        </el-table-column>
        <el-table-column label="二次付款" prop="pay_sec">
          <template slot-scope="scope">
            <el-input v-model="scope.row.pay_sec" />
          </template>
        </el-table-column>
        <el-table-column label="尾付款" prop="pay_end">
          <template slot-scope="scope">
            <el-input v-model="scope.row.pay_end" />
          </template>
        </el-table-column>
      </el-table>
      <div class="form-unit">
        <span class="mvc-title-left"> 违约责任 </span>
      </div>
      <el-table :data="s_top">
        <el-table-column label="操作" prop="" width="60">
          <template slot-scope="scope">
            <el-link @click="appendRow(s_top,scope)" type='primary'><i class='el-icon-plus' title='增加行' /></el-link>
            <el-link @click="delRow(s_top,scope)" type='danger'><i class='el-icon-minus' title='删除行' /></el-link>
          </template>
        </el-table-column>
        <el-table-column label="责任选择" prop="break_duty">
          <template slot-scope="scope">
            {{scope.row.break_duty}}
            <el-button @click="popLiabilityContract('break_duty','break_duty')" type="success" size="mini"><i class="fa fa-edit"></i>选择</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="form-unit">
        <span class="mvc-title-left"> 其他要求 </span>
      </div>
      <el-table :data="s_top">
        <el-table-column label="操作" prop="" width="60">
          <template slot-scope="scope">
            <el-link @click="appendRow(s_top,scope)" type='primary'><i class='el-icon-plus' title='增加行' /></el-link>
            <el-link @click="delRow(s_top,scope)" type='danger'><i class='el-icon-minus' title='删除行' /></el-link>
          </template>
        </el-table-column>
        <el-table-column label="选择" prop="description">
          <template slot-scope="scope">
            {{scope.row.description}}
            <el-button @click="popOtherRequirements('description','demand')" type="success" size="mini"><i class="fa fa-edit"></i>选择</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div>
      </div>
      <div class="form-unit">
        <span class="mvc-title-left"> 备注 </span>
      </div>
      <div>
        <el-row>
          <el-col :span="24">
            <el-form-item label="内部备注" prop="quo_insides">
              <el-input type="textarea" v-model="quo_price.quo_insides" ttparea=350></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </div>
      <el-button @click="increaseOfferSubmit('')" type='success' size="mini"><i class='fa fa-check'></i>保存</el-button>
      <el-button @click="gotoPage('/crm/sale/contract/CartogramSaleContract?'+vueparams+'')" type='primary' size="mini"><i class='fa fa-reply'></i>返回</el-button>
    </el-form>
    <el-dialog :visible.sync="SelectCustomersSaleVisible" append-to-body>
      <SelectCustomersSale v-if="SelectCustomersSaleVisible" ref="SelectCustomersSale" :popparams="popparams"> </SelectCustomersSale>
    </el-dialog>
    <el-dialog :visible.sync="ChooseContactsVisible" append-to-body>
      <ChooseContacts v-if="ChooseContactsVisible" ref="ChooseContacts" :popparams="popparams"> </ChooseContacts>
    </el-dialog>
    <el-dialog :visible.sync="ProductChoceVisible" append-to-body>
      <ProductChoce v-if="ProductChoceVisible" ref="ProductChoce" :popparams="popparams"> </ProductChoce>
    </el-dialog>
    <el-dialog :visible.sync="ResponsibilityChoice2Visible" append-to-body>
      <ResponsibilityChoice2 v-if="ResponsibilityChoice2Visible" ref="ResponsibilityChoice2" :popparams="popparams"> </ResponsibilityChoice2>
    </el-dialog>
    <el-dialog :visible.sync="LiabilityContractVisible" append-to-body>
      <LiabilityContract v-if="LiabilityContractVisible" ref="LiabilityContract" :popparams="popparams"> </LiabilityContract>
    </el-dialog>
    <el-dialog :visible.sync="OtherRequirementsVisible" append-to-body>
      <OtherRequirements v-if="OtherRequirementsVisible" ref="OtherRequirements" :popparams="popparams"> </OtherRequirements>
    </el-dialog>
  </div>
</template>
<script>
  import request from '@/utils/request'
  import SelectCustomersSale from "@/views/crm/sale/contract/SelectCustomersSale";
  import ChooseContacts from "@/views/crm/sale/contract/ChooseContacts";
  import ProductChoce from "@/views/crm/sale/ProductChoce";
  import ResponsibilityChoice2 from "@/views/crm/sale/ResponsibilityChoice2";
  import LiabilityContract from "@/views/crm/sale/LiabilityContract";
  import OtherRequirements from "@/views/crm/sale/OtherRequirements";
  export default {
    name: 'IncreaseOffer',
    components: {
      SelectCustomersSale,
      ChooseContacts,
      ProductChoce,
      ResponsibilityChoice2,
      LiabilityContract,
      OtherRequirements,
    },
    props: ['popparams'],
    data() {
      return {
        SelectCustomersSaleVisible: false,
        SelectCustomersSaleValue: null,
        SelectCustomersSaleDesc: null,
        ChooseContactsVisible: false,
        ChooseContactsValue: null,
        ChooseContactsDesc: null,
        ProductChoceVisible: false,
        ProductChoceValue: null,
        ProductChoceDesc: null,
        ResponsibilityChoice2Visible: false,
        ResponsibilityChoice2Value: null,
        ResponsibilityChoice2Desc: null,
        LiabilityContractVisible: false,
        LiabilityContractValue: null,
        LiabilityContractDesc: null,
        OtherRequirementsVisible: false,
        OtherRequirementsValue: null,
        OtherRequirementsDesc: null,
        vueparams: this.getVUEParams(""),
        quo_price: {
          quo_barcode: null,
          quo_num: null,
          quo_theme: null,
          quo_client: null,
          quo_contact: null,
          quo_address: null,
          quo_finishdate: null,
          quo_faildate: null,
          quo_state: null,
        },
        s_top: [],
        loading: false,
        rules: {
          quo_num: [{
            required: true,
            message: "合同编号不能为空",
            trigger: 'blur',
          }],
          quo_theme: [{
            required: true,
            message: "合同主题不能为空",
            trigger: 'blur',
          }],
          quo_finishdate: [{
            required: true,
            message: "签订时间不能为空",
            trigger: 'blur',
          }],
          quo_faildate: [{
            required: true,
            message: "失效日期不能为空",
            trigger: 'blur',
          }],
        }
      }
    },
    created() {
      this.getData();
    },
    updated() {},
    mounted() {},
    methods: {
      getData() {
        request({
          method: 'get',
          url: '/xcapi/VUEAction/crm/sale/contract/IncreaseOffer/increaseOffer?' + this.vueparams,
        }).then(data => {
          for (var k in data) {
            if (Array.isArray(data[k])) {
              this[k] = data[k];
            } else {
              $.extend(this[k], data[k]);
            }
          }
        })
      },
      increaseOfferSubmit(_params) {
        this.$refs["form"].validate(valid => {
          if (valid) {
            request({
              method: 'post',
              url: '/xcapi/VUEAction/crm/sale/contract/IncreaseOffer/increaseOfferSubmit?' + _params + this.vueparams,
              data: this.postData()
            }).then(data => {
              this.gotoPage("/crm/sale/contract/CartogramSaleDet/cartogramSaleDet?" + this.vueparams, data);
              this.msgSuccess(data.msg);
            })
          } else {
            this.msgError("必填项错误");
          }
        });
      },
      chartPublicContractAddSubmit(_params) {
        this.$refs["form"].validate(valid => {
          if (valid) {
            request({
              method: 'post',
              url: '/xcapi/VUEAction/crm/sale/contract/IncreaseOffer/chartPublicContractAddSubmit?' + _params + this.vueparams,
              data: this.postData()
            }).then(data => {
              this.gotoPage("/crm/sale/contract/CartogramSaleDet/cartogramSaleDet?" + this.vueparams, data);
              this.msgSuccess(data.msg);
            })
          } else {
            this.msgError("必填项错误");
          }
        });
      },
      popSelectCustomersSale(desc, value) {
        this.SelectCustomersSaleVisible = true;
        this.SelectCustomersSaleDesc = desc;
        this.SelectCustomersSaleValue = value;
      },
      closeSelectCustomersSale(value, desc) {
        this.SelectCustomersSaleVisible = false;
        this.$set(this.quo_price, this.SelectCustomersSaleDesc, desc);
        this.$set(this.quo_price, this.SelectCustomersSaleValue, value);
      },
      popChooseContacts(desc, value) {
        this.ChooseContactsVisible = true;
        this.ChooseContactsDesc = desc;
        this.ChooseContactsValue = value;
      },
      closeChooseContacts(value, desc) {
        this.ChooseContactsVisible = false;
        this.$set(this.quo_price, this.ChooseContactsDesc, desc);
        this.$set(this.quo_price, this.ChooseContactsValue, value);
      },
      popProductChoce(desc, value) {
        this.ProductChoceVisible = true;
        this.ProductChoceDesc = desc;
        this.ProductChoceValue = value;
      },
      closeProductChoce(value, desc) {
        this.ProductChoceVisible = false;
        this.$set(this.s_top, this.ProductChoceDesc, desc);
        this.$set(this.s_top, this.ProductChoceValue, value);
      },
      popResponsibilityChoice2(desc, value) {
        this.ResponsibilityChoice2Visible = true;
        this.ResponsibilityChoice2Desc = desc;
        this.ResponsibilityChoice2Value = value;
      },
      closeResponsibilityChoice2(value, desc) {
        this.ResponsibilityChoice2Visible = false;
        this.$set(this.s_top, this.ResponsibilityChoice2Desc, desc);
        this.$set(this.s_top, this.ResponsibilityChoice2Value, value);
      },
      popLiabilityContract(desc, value) {
        this.LiabilityContractVisible = true;
        this.LiabilityContractDesc = desc;
        this.LiabilityContractValue = value;
      },
      closeLiabilityContract(value, desc) {
        this.LiabilityContractVisible = false;
        this.$set(this.s_top, this.LiabilityContractDesc, desc);
        this.$set(this.s_top, this.LiabilityContractValue, value);
      },
      popOtherRequirements(desc, value) {
        this.OtherRequirementsVisible = true;
        this.OtherRequirementsDesc = desc;
        this.OtherRequirementsValue = value;
      },
      closeOtherRequirements(value, desc) {
        this.OtherRequirementsVisible = false;
        this.$set(this.s_top, this.OtherRequirementsDesc, desc);
        this.$set(this.s_top, this.OtherRequirementsValue, value);
      },
    },
  }
</script>
